
const first = new Promise((resolve,reject)=>{
    setTimeout(resolve, 0, '兑现(first)');
});
first.then( result => console.log( 'first then: ', result ) );

const second = new Promise((resolve,reject)=>{
    setTimeout(resolve, 1000, '兑现(second)');
});
second.then( result => console.log( 'second then: ', result ) );

const third = new Promise((resolve,reject)=>{
    setTimeout(reject, 500, '拒绝(third)');
});
third.catch( result => console.log( 'third catch: ', result ) );

const promises = [ first, second, third ];

const last = Promise.allSettled( promises );
last.then( results => results.forEach( r => console.log(r) ) )
    .catch( reason => console.log( reason ) );

// 总结
// Promise.allSettled( iterable )
// 1、参数iterable表示一组Promise实例，可以是 Array、Set、Map
// 2、Promise.allSettled 方法仅返回单个 Promise实例
// 3、等到参数iterable中所有的Promise实例都已经被确定时，allSettled所返回的Promise实例就被兑现了
//   (所谓的被确定是指 Promise实例的状态要么是fulfilled，要么是rejected，总之不是 pending)
// 4、在allSettled所返回的Promise实例中包含了iterable中所有Promise实例的状态和结果:
//    [ {status: 'fulfilled', value: '兑现(first)'}, 
//      {status: 'fulfilled', value: '兑现(second)'},
//      {status: 'rejected', reason: '拒绝(third)' }]